<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        div {
            width: 270px;
            height: 120px;
            background-color: aqua;
            margin: 100px auto;
            padding: 10px;
            text-align: center;
        }

        p {
            display: block;
            font-size: 20px;
            font-weight: 700;
            color: #fff;
            margin-bottom: 20px;
        }

        span {
            width: 40px;
            height: 40px;
            background-color: #555;
            color: #fff;
            border-radius: 50%;
            font-size: 20px;
            font-weight: 700;
        }
    </style>
</head>

<body>
    <div>
        <p>距离端午还有</p>
        <span class="day"></span>天
        <span class="hour"></span>时
        <span class="minute"></span>分
        <span class="second"></span> 秒
    </div>

    <script>
        const oDay = document.querySelector('.day');
        const oHour = document.querySelector('.hour')
        const oMinute = document.querySelector('.minute')
        const oSecond = document.querySelector('.second')
        const inputTime = +new Date('2022-6-3 00:00:00');

        countDown(inputTime);
        setInterval(countDown, 1000,inputTime);



        function countDown(tt) {
            let nowTime = +new Date()
            let times = (tt - nowTime) / 1000;

            let s = parseInt(times % 60);
            s = s < 10 ? '0' + s : s;
            oSecond.innerHTML=s;

            let m = parseInt(times/60 % 60);
            m = m < 10 ? '0' + m : m;
            oMinute.innerHTML=m;

            let h = parseInt(times/60/60 % 24);
            h = h < 10 ? '0' + h : h;
            oHour.innerHTML=h;

            let d = parseInt(times/60/60/24);
            oDay.innerHTML=d;
        }

    </script>
</body>

</html>